/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DecisionTree.io;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import DecisionTree.*;
/**
 *
 * @author Pham Thanh
 */
public class ReadWriteDecisionTree {
  public void writeToFile(String fileName,DecisionTree tree) throws FileNotFoundException, IOException{
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(fileName));
//        Iterator iterator=breadthFirstIterator();
//        while(iterator.hasNext()){
//            ScoreTestNode stn=(ScoreTestNode) iterator.next();
//            oos.writeObject(stn);
//        }
//
        oos.writeObject(tree);
        oos.close();
    }

    public DecisionTree readFromFile(String fileName) throws FileNotFoundException, IOException, ClassNotFoundException{
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream(fileName));
        DecisionTree tree= (DecisionTree) ois.readObject();
        ois.close();
        return tree;
    }

}
